import {XF_APP_CONFIG} from '@/config'
import {getLocaleOnServer} from '@/i18n/server'
import './styles/globals.css'
import type {Metadata, ResolvingMetadata} from 'next'
import {v4} from 'uuid'
import './styles/markdown.scss'

type Props = {
  params: Promise<{ id: string }>
  searchParams: Promise<{ [key: string]: string | string[] | undefined }>
}

export async function generateMetadata(
): Promise<Metadata> {
  // read route params
  return {
    title: '智能管网专家',
  }
}

const LocaleLayout = ({
  children,
}: {
  children: React.ReactNode
}) => {
  const locale = getLocaleOnServer()
  /* const isInQt = headers().get('') */return (
    <html lang={locale ?? 'en'} className="h-full">
    <head>
      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
      <link type="text/css" rel="stylesheet" href="/style/global.css"/>
      <script dangerouslySetInnerHTML={{
        __html: `
          if(typeof globalThis === "undefined") {
  window.globalThis = window;
}
`,
      }}
      />
      <script src="/js/def.js"></script>
      <script dangerouslySetInnerHTML={{
        __html: `var APPID = "${XF_APP_CONFIG.APPID}";
          var API_SECRET = "${XF_APP_CONFIG.API_SECRET}";
          var API_KEY = "${XF_APP_CONFIG.API_KEY}";`,
      }}
      />
      <script dangerouslySetInnerHTML={{
        __html: `
            window.__SSID = localStorage.getItem("chat-session_id") || "${v4()}";
            localStorage.setItem("chat-session_id", window.__SSID);
            `,
      }}
      ></script>

      <script src="/qt/qwebchannel.js"></script>
      <script src="/qt/qwebchannel-bridge.js"></script>
      <script src="/xf/crypto-js.js"></script>
      <script src="/xf/build/index.umd.js"></script>
    </head>
    <body className="h-full overflow-y-hidden">
        <div className="overflow-x-auto">
          <div className="w-screen h-screen min-w-[300px]">
            {children}
          </div>
        </div>
      </body>
    </html>
  )
}

export default LocaleLayout
